<template>
    <view style="padding-bottom: 120rpx;">
        <j-cell-group title="系统信息">
            <j-cell title="设备序列号" :tips="info.SerialNo" :more="false"></j-cell>
            <j-cell title="设备登录名" :tips="device.devUserName" :more="false"></j-cell>
            <j-cell title="设备硬件" :tips="info.HardWare" :more="false"></j-cell>
            <j-cell title="硬件版本号" :tips="info.HardWareVersion" :more="false"></j-cell>
            <j-cell title="软件版本号" :tips="info.SoftWareVersion" :more="false"></j-cell>
            <j-cell title="加密版本号" :tips="info.EncryptVersion" :more="false"></j-cell>
            <j-cell title="发布日期" :tips="info.BuildTime" :more="false"></j-cell>
            <j-cell title="修改日期" :tips="info.UpdataTime" :more="false"></j-cell>
            <j-cell title="修改内容" :tips="updataTypeText" :more="false"></j-cell>
		</j-cell-group>
		<j-cell-group title="状态">
			<j-cell title="报警输入状态" v-if="workState.AlarmIn" :tips="Number(parseInt(workState.AlarmIn,16).toString(10)) === 0 ? '无警告':'警告'" :more="false"></j-cell>
			<j-cell title="报警输出状态" v-if="workState.AlarmOut" :tips="Number(parseInt(workState.AlarmOut,16).toString(10)) === 0 ? '无警告':'警告'" :more="false"></j-cell>
			<j-cell title="视频遮挡状态" v-if="workState.VideoBlind" :tips="Number(parseInt(workState.VideoBlind,16).toString(10)) === 0 ? '无警告':'警告'" :more="false"></j-cell>
			<j-cell title="视频丢失状态" v-if="workState.VideoLoss" :tips="Number(parseInt(workState.VideoLoss,16).toString(10)) === 0 ? '无警告':'警告'" :more="false"></j-cell>
			<j-cell title="移动侦测状态" v-if="workState.VideoMotion" :tips="Number(parseInt(workState.VideoMotion,16).toString(10)) === 0 ? '无警告':'警告'" :more="false"></j-cell>
        </j-cell-group>
		<view class="bottom-fixed">
			<view style="display: flex; justify-content: space-between; align-items: center;">
			    <button type="default" size="mini" @tap="bindtapReset" style="margin-right:10rpx;">恢复出厂设置</button>
			    <button type="default" size="mini" @tap="bindtapRestart">设备重启</button>
			</view>
		</view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            token: '',

            info: {
                SerialNo: '',
                HardWare: '',
                HardWareVersion: '',
                SoftWareVersion: '',
                EncryptVersion: '',
                BuildTime: '',
                UpdataTime: ''
            },
			workState:{
				
			},

            updataTypeText: '',

            device: {
                devUserName: ''
            },
            deviceNo:''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        this.token = options.token
        this.deviceNo = options.deviceNo
        this.getinfo();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        // 第4步-3-1 获取设备基础信息
        getinfo() {
            uni.showLoading({
                title: '获取设备基础信息...'
            });
            let token = this.token;
            const data = {
                Name: 'SystemInfo'
            };
            getApp().globalData.api.getinfo(data, token, (result) => {
                console.log('获取设备基础信息:', result);
                uni.hideLoading({
                    success: (res) => {
						this.info = result.SystemInfo
						let updataType = getApp().globalData.constant.UPDATA_TYPE;
						Object.keys(updataType).forEach((item) => {
							if (item === this.info.UpdataType) {
								this.updataTypeText = updataType[item]
							}
						});
						this.getWorkState()
                    }
                });
            });
        },
		// 状态 
		getWorkState() {
		    uni.showLoading({
		        title: '获取设备状态信息...'
		    });
		    let token = this.token;
		    const data = {
		        Name: 'WorkState'
		    };
		    getApp().globalData.api.getinfo(data, token, (result) => {
		        console.log('获取设备状态信息:', result);
		        uni.hideLoading({
		            success: (res) => {
						this.workState = result.WorkState.AlarmState
		            }
		        });
		    });
		},

        // 恢复出厂设置
        bindtapReset() {
            uni.showModal({
                title: '提示',
                content: '确认恢复出厂设置？',
                success: (res) => {
                    if (res.confirm) {
                        uni.showLoading({
                            title: '恢复中...'
                        });
                        let token = this.token;
                        let data = {
                            Name: 'OPDefaultConfig',
                            OPDefaultConfig: {
                                Account: true,
                                Alarm: true,
                                CommPtz: true,
                                Encode: true,
                                General: true,
                                NetCommon: true,
                                NetServer: true,
                                Preview: true,
                                Record: true,
                                XMModeSwitch: true,
                                CameraPARAM: true
                            }
                        };
                        getApp().globalData.api.opdev(data, token, (result) => {
                            uni.hideLoading({
                                success: (res) => {
                                    console.log(result);
                                    getApp().globalData.mqtt.getUnsubscribe(this.deviceNo,'device')
                                }
                            });
                        });
                    }
                }
            });
        },

        // 重启
        bindtapRestart() {
            uni.showModal({
                title: '提示',
                content: '确认重启设备？',
                success: (res) => {
                    if (res.confirm) {
                        uni.showLoading({
                            title: '重启中...'
                        });
                        let token = this.token;
                        let data = {
                            Name: 'OPMachine',
                            OPMachine: {
                                Action: 'Reboot'
                            }
                        };
                        getApp().globalData.api.opdev(data, token, (result) => {
                            uni.hideLoading({
                                success: (res) => {
                                    console.log(result);
                                }
                            });
                        });
                    }
                }
            });
        }
    }
};
</script>
<style></style>
